Chapter 12: Troubleshooting: Production Diagnostics, Common Pitfalls, and Failure Modes

Deploying hardened LangChain systems to enterprise production introduces failure modes spanning authentication boundaries, policy evaluation timeouts, vector retrieval pruning, and agent reasoning loops. When policy enforcement is strictly fail-closed, an upstream misconfiguration or unexpected token format halts execution rather than failing silently.

This chapter provides a concise diagnostic reference for production operations. Using our Enterprise Incident Assistant demonstrator as a concrete case study, we examine real-world failure patterns and demonstrate how to diagnose and resolve them across your own enterprise AI applications.


Exception Taxonomy & Diagnostic Reason Codes

The security extension intercepts operations across multiple Policy Enforcement Points (PEPs) and raises typed exceptions derived from SecurityAuthorizationError. Every denial carries a standardized diagnostic_reason to facilitate immediate troubleshooting:

Typed Exception Diagnostic Reason Code Enforcement Point Primary Root Cause
TenantIsolationError TENANT_MISMATCH SecureRunnable / Agent Gate Caller tenant does not match target agent tenant boundary.
AgentAccessDeniedException INSUFFICIENT_CLEARANCE
MISSING_REQUIRED_ROLE
SecureRunnable / Agent Gate Caller role not in authorized role graph, or clearance rank too low.
ToolExecutionDeniedError PARAMETER_CONSTRAINT_FAILED
FAIL_CLOSED_NULL_ENTITY
@secured_tool PEP CEL argument expression failed, or entity resolver returned None.
ToolExecutionFeedbackException STATUS_BLOCKED_BY_POLICY @secured_tool PEP Informational tool denied; returns safe refusal payload to LLM.
IngestionRejectedException INGEST_REJECTED SecureVectorStoreIngestor Chunk missing mandatory sec:* metadata in strict fail-closed mode.
SecurityAuthorizationError INVALID_HMAC SecureRetriever Tampered metadata or HMAC secret mismatch on stored vector chunks.
PromptInjectionDetectedException PROMPT_INJECTION_DETECTED RunnableGuard / Scanner Inbound prompt matched injection heuristics or structural exploit.
AuditBufferFullException AUDIT_BUFFER_FULL AuditManager Worker SIEM collector unresponsive; buffer overflowed under backpressure.

1. Identity & Context Propagation Pitfalls

Symptom: Requests Fall Back to Anonymous (Clearance 0, Deny-All)

Authorized users suddenly receive AgentAccessDeniedException or queries return zero vector results because the retriever injected the unauthenticated sentinel: {"sec:tenant_id": "__DENY_ALL__"}.

Case Study: Async Task Handoff in the Incident Assistant

In the Incident Assistant, incoming FastAPI requests resolve JWT claims via IdentityBridge and store the identity in SecurityContextHolder (using Python contextvars). However, when delegating work from TriageAgent to RemediationAgent, or dispatching tasks to worker threads, Python's contextvars do not automatically cross thread boundaries.


2. Policy Decision Point (PDP) & Circuit Breaker Failures

Symptom: Intermittent Failures with "PDP circuit breaker is OPEN"

The application abruptly halts all tool and agent executions with fail-closed rejections, even for privileged administrators.

Symptom: Stale Authorization After Identity or Role Revocation


3. Knowledge Ingestion & Vector Retrieval Traps

Symptom: Ingestion Batch Aborts Atomically

Symptom: Top-K Starvation in RAG Pipelines

The vector store contains matching runbooks, but the retriever returns only 1 or 2 chunks instead of the requested k=5, causing the LLM to hallucinate or state that it lacks sufficient context.

Symptom: Chunks Rejected with "INVALID_HMAC"


4. Tool Interception, CEL Rules, and Agent Looping

Symptom: CEL Denials with "FAIL_CLOSED_NULL_ENTITY"

Symptom: Runaway Agent Terminated with "TOOL_RETRY_BUDGET_EXCEEDED"


5. Telemetry Backpressure & Sanitization Over-Redaction

Symptom: LLM Receives Mangled Prompts or Broken Code

Symptom: High Volume of "DROP_OLDEST_WITH_METRIC" SIEM Alerts


Production Health Check Checklist

Before promoting any LangChain-based service to production, verify these core security invariants:

Inspection Item Target Configuration Expected Production Behavior
Identity Handoff RunnableConfig["configurable"]["security_identity"] Identity preserved across multi-agent hops; zero fallback to anonymous.
PDP Fallback fallback_engine=base_engine Graceful in-process RBAC fallback if remote OPA cluster is partitioned.
RAG Oversampling security.retriever.oversampling >= 3.0 Sufficient candidate chunks survive post-retrieval clearance pruning.
Tool Denial Mode HARD_ABORT (mutative) / MODEL_FEEDBACK (read-only) Destructive actions fail instantly; read-only tools guide LLM gracefully.
PII Scope security.pii.redaction.scope=audit_only In-flight prompts unmodified; audit logs and SIEM streams scrubbed.
Audit Buffer Ring buffer active with background daemon thread Security telemetry dispatched off-inference-path with 0ms latency penalty.

For complete property specifications, default thresholds, environment variable overrides, and component mappings, consult Chapter 13: Unified Configuration Reference.